package com.ls.dao.user;

import com.ls.dao.BaseDao;
import com.ls.dao.BasicDAO;
import com.ls.pojo.User;
import com.ls.util.jdbcUtils.JDBCUtilsByDruid;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author 李朔
 * @version 1.0
 */
public class UserDaoImplByBasicDAO  extends BasicDAO implements UserDao {

    public User getLoginUser(Connection connection,String userCode) throws SQLException {
        PreparedStatement preparedStatement=null;
        ResultSet resultSet = null;
        User user = null;
        connection=JDBCUtilsByDruid.getConnection();
            String sql = "select * from smbms_user where userCode=?";
            Object[] params = {userCode};
            try {
                resultSet =querySingle_new(connection,preparedStatement,sql,params);
                if(resultSet.next()){
                    user=new User();
                    user.setId(resultSet.getInt("id"));
                    user.setUserCode(resultSet.getString("userCode"));
                    user.setUserName(resultSet.getString("userName"));
                    user.setUserPassword(resultSet.getString("userPassword"));
                    user.setGender(resultSet.getInt("gender"));
                    user.setBirthday(resultSet.getDate("birthday"));
                    user.setPhone(resultSet.getString("phone"));
                    user.setAddress(resultSet.getString("address"));
                    user.setUserRole(resultSet.getInt("userRole"));
                    user.setCreatedBy(resultSet.getInt("createdBy"));
                    user.setCreationDate(resultSet.getTimestamp("creationDate"));
                    user.setModifyBy(resultSet.getInt("modifyBy"));
                    user.setModifyDate(resultSet.getTimestamp("modifyDate"));
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }finally {
                //关闭
                JDBCUtilsByDruid.close(resultSet,preparedStatement,connection);
            }

        return user;
    }

    public int updatePwd(Connection connection, int id, String password) throws SQLException {
        return 0;
    }

    public int getUserCount(Connection connection, String username, int userRole) {
        return 0;
    }

    public List<User> getUserList(Connection connection, String userName, int userRole, int currentPageNo, int pageSize) throws Exception {
        return null;
    }

    public boolean addUser(Connection connection, User user) {
        return false;
    }

}
